<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
    >
      <el-table-column
        prop="id"
        label="商户ID"
      />
      <el-table-column
        prop="name"
        label="商户名称"
      />
      <el-table-column
        prop="corporation"
        label="法人"
      />
      <el-table-column
        prop="address"
        label="地址"
      />
      <el-table-column
        prop="type"
        label="类型"
      >
        <template slot-scope="scope">
          {{ scope.row.type == 0?'公司化公寓':'个人职业房东' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        label="状态"
      >
        <template slot-scope="scope">
          {{ scope.row.status == 1?'审核通过':scope.row.status == 2?'待审核':'审核未通过' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="uname"
        label="管理员"
      />
      <el-table-column
        prop="createTime"
        label="申请时间"
      />
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.row)"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :current-page="form.pageNum"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="form.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />

    <el-dialog title="审核" :visible.sync="dialogFormVisible">
      <el-form :model="auditForm">
        <el-form-item label="商户名称:" :label-width="formLabelWidth">
          <el-input v-model="auditForm.name" readonly="readonly" autocomplete="off" v-text="auditForm.name" />
        </el-form-item>
        <el-form-item label="法人:" :label-width="formLabelWidth">
          <el-input v-model="auditForm.corporation" readonly="readonly" autocomplete="off" v-text="auditForm.corporation" />
        </el-form-item>
        <el-form-item label="地址:" :label-width="formLabelWidth">
          <el-input v-model="auditForm.address" readonly="readonly" autocomplete="off" v-text="auditForm.address" />
        </el-form-item>
        <el-form-item label="状态:" :label-width="formLabelWidth">
          <el-input v-model="auditForm.status" readonly="readonly" autocomplete="off" v-text="audit" />
        </el-form-item>
        <el-form-item label="管理员:" :label-width="formLabelWidth">
          <el-input v-model="auditForm.uname" readonly="readonly" autocomplete="off" v-text="auditForm.uname" />
        </el-form-item>
        <el-form-item label="申请时间:" :label-width="formLabelWidth">
          <el-input v-model="auditForm.createTime" readonly="readonly" autocomplete="off" v-text="auditForm.createTime" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="update2">通过</el-button>
        <el-button type="primary" @click="update">不通过</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>

</template>

<script>
export default {
  data() {
    return {
      audit: '',
      tableData: [],
      total: 0,
      dialogFormVisible: false,
      formLabelWidth: '120px',
      form: {
        pageNum: 1,
        pageSize: 10
      },
      auditForm: {
        id: '',
        name: '',
        corporation: '',
        address: '',
        type: '',
        status: 0,
        uname: '',
        createTime: ''
      }
    }
  },
  created() {
    this.initDate()
  },
  methods: {
    initDate() {
      this.axios.post('http://localhost:80/api/sys/wish/business/list', this.form).then((res) => {
        this.tableData = res.data.list
        this.form.pageNum = res.data.pageNum
        this.form.pageSize = res.data.pageSize
        this.total = res.data.total
        console.log(res.data)
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.form.pageSize = val
      this.initDate()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.form.pageNum = val
      this.initDate()
    },
    handleEdit(row) {
      console.log(row)
      this.auditForm = row
      // eslint-disable-next-line eqeqeq
      if (row.status == 1) {
        this.audit = '审核通过'
        // eslint-disable-next-line eqeqeq
      } else if (row.status == 2) {
        this.audit = '待审核'
      } else {
        this.audit = '审核未通过'
      }
      this.dialogFormVisible = true
    },
    update() {
      this.axios.post('http://localhost:80/api/sys/wish/business/update', this.auditForm).then((res) => {
        if (res) {
          alert('操作成功')
          this.initDate()
          this.dialogFormVisible = false
        }
      })
    },
    update2() {
      this.axios.post('http://localhost:80/api/sys/wish/business/update2', this.auditForm).then((res) => {
        if (res) {
          alert(res.data.msg)
          this.initDate()
          this.dialogFormVisible = false
        }
      })
    }
  }
}
</script>

